<% if script.active? 
	case script.script_type_id
		when 1, 2 %>
			<div id="install-area">
				<%=link_to t('scripts.install'),
					params[:version].nil? ? script_user_js_path(script, :name => script.url_name, :locale_override => nil) : script_user_js_path(script, :version => params[:version], :name => script.url_name, :locale_override => nil) + '&d=.user.js',
					{
						class: 'install-link',
						'data-ping-url' => script_install_ping_path(script, :authenticity_token => session[:_csrf_token], :locale_override => nil),
						'data-is-previous-version' => !params[:version].nil?,
						rel: 'nofollow',
						'data-script-name' => script.default_name,
						'data-script-namespace' => script.namespace,
						'data-script-version' => @script_version.version,
						'data-update-label' => t('scripts.update', version: @script_version.version),
						'data-downgrade-label' => t('scripts.downgrade', version: @script_version.version),
						'data-reinstall-label' => t('scripts.reinstall', version: @script_version.version),
					} %><%=link_to t('scripts.install_help'), help_installing_user_scripts_path, {:class => 'install-help-link', :title => t('scripts.install_help_title'), :rel => 'nofollow'}%>

				<% if user_signed_in?
					sets_direct_inclusion = []
					sets_direct_exclusion = []
					sets_indirect_inclusion = []
					sets_not_included = []
					current_user.script_sets.each do |set|
						if set.child_script_inclusions.include?(script)
							sets_direct_inclusion << set
							next
						end
						if set.child_script_exclusions.include?(script)
							sets_direct_exclusion << set
							next
						end
						set_script_ids = cache_with_log([set, script_subset]) do
							set.scripts(script_subset).map{|s| s.id}
						end
						if set_script_ids.include?(script.id)
							sets_indirect_inclusion << set
						else
							sets_not_included << set
						end
					end
					in_sets = sets_direct_inclusion + sets_indirect_inclusion
					user_has_favorites_set = current_user.script_sets.find{|s| s.favorite}
					%>
					<%=form_tag(add_to_script_set_path, {:class => 'script-in-sets'}) do |f| %>
						<% if in_sets.empty? %>
							<%=t('scripts.sets_label_no_sets')%>
						<% else %>
							<%=t('scripts.sets_label')%>
							<%=ScriptSet.favorites_first(in_sets).map{|s| link_to(s.display_name, scripts_path(:set => s.id)).html_safe}.join(', ').html_safe%>
						<% end %>
						<select name="action-set">
							<% if !user_has_favorites_set %>
								<option value="ai-fav"><%=t('scripts.sets_add_inclusion', :set_name => t('script_sets.favorites_name'))%></option>
							<% end %>
							<% ScriptSet.favorites_first(sets_direct_inclusion).each do |set| %>
								<option value="ri-<%=set.id%>"><%=t('scripts.sets_remove_inclusion', :set_name => set.display_name)%></option>
							<% end
							sets_direct_exclusion.each do |set| %>
								<option value="re-<%=set.id%>"><%=t('scripts.sets_remove_exclusion', :set_name => set.display_name)%></option>
							<% end
							sets_indirect_inclusion.each do |set| %>
								<option value="ae-<%=set.id%>"><%=t('scripts.sets_add_exclusion', :set_name => set.display_name)%></option>
							<% end
							ScriptSet.favorites_first(sets_not_included).each do |set| %>
								<option value="ai-<%=set.id%>"><%=t('scripts.sets_add_inclusion', :set_name => set.display_name)%></option>
							<% end %>
							<option value="ai-new"><%=t('scripts.sets_add_to_new')%></option>
						</select>
						<input type="hidden" name="script_id" value="<%=script.id%>">
						<input type="submit" value="→">
					<% end %>
				<% end %>
			</div>

		<% when 3 %>
			<p>
				<% if params[:version].nil?
					library_code_snippet = "<code>// @require #{script_library_js_url(script, :version => script_version.id, :name => script.url_name, :locale_override => nil)}</code>"
				else
					library_code_snippet = "<code>// @require #{script_library_js_url(script, :version => params[:version], :name => script.url_name, :locale_override => nil)}</code>"
				end %>
				<%=t('scripts.library_instructions_html', :code => library_code_snippet.html_safe)%>
			</p>
	<% end %>
<% elsif script.deleted? %>
	<p><%=t('scripts.deleted_notice')%>	<% if !script.delete_reason.nil? %><%=script.delete_reason%><%end%></p>
<% elsif !params[:version].nil? %>
	<p id="under-review-notice"><%=t('scripts.inactive_pending_changes_for_previous_version', site_name: site_name)%></p>
<% else %>
	<p id="under-review-notice"><%=t('scripts.inactive_pending_changes', site_name: site_name)%></p>
<% end %>

